Skip to content

Conversation

brunodf-snps
Copy link
Contributor

These statements conditionally select between diagnostics of different categories (common vs. sema). Although the diagnostic IDs do not overlap between categories, they are organized in different enums, and this raises warnings in specific compilers. The clang warning suggest this behavior is deprecated in C++20 (the warning is ignored by default in C++17 mode). By converting the diagnostic IDs to unsigned, we avoid the issue.

These statements conditionally select between diagnostics of different
categories (common vs. sema). Although the diagnostic IDs do not overlap
between categories, they are organized in different enums, and this
raises warnings in specific compilers. The clang warning suggest this
behavior is deprecated in C++20. By converting the diagnostic IDs to
unsigned, we avoid the issue.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 17, 2025
@brunodf-snps
Copy link
Contributor Author

brunodf-snps commented Sep 17, 2025

Example of compiler warnings: https://godbolt.org/z/T9hc8M744

@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2025

@llvm/pr-subscribers-clang

Author: Bruno De Fraine (brunodf-snps)

Changes

These statements conditionally select between diagnostics of different categories (common vs. sema). Although the diagnostic IDs do not overlap between categories, they are organized in different enums, and this raises warnings in specific compilers. The clang warning suggest this behavior is deprecated in C++20 (the warning is ignored by default in C++17 mode). By converting the diagnostic IDs to unsigned, we avoid the issue.


Full diff: https://github.com/llvm/llvm-project/pull/159316.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaDeclAttr.cpp (+4-3)
  • (modified) clang/lib/Sema/SemaStmtAttr.cpp (+4-3)
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 44906456f3371..12f06070a3db2 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6836,9 +6836,10 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
   if (AL.getKind() == ParsedAttr::UnknownAttribute ||
       !AL.existsInTarget(S.Context.getTargetInfo())) {
     if (AL.isRegularKeywordAttribute() || AL.isDeclspecAttribute()) {
-      S.Diag(AL.getLoc(), AL.isRegularKeywordAttribute()
-                              ? diag::err_keyword_not_supported_on_target
-                              : diag::warn_unhandled_ms_attribute_ignored)
+      S.Diag(AL.getLoc(),
+             AL.isRegularKeywordAttribute()
+                 ? (unsigned)diag::err_keyword_not_supported_on_target
+                 : (unsigned)diag::warn_unhandled_ms_attribute_ignored)
           << AL.getAttrName() << AL.getRange();
     } else {
       S.DiagnoseUnknownAttribute(AL);
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 77aa7164d4555..66785c7deee57 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -673,9 +673,10 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
         (S.Context.getLangOpts().SYCLIsDevice && Aux &&
          A.existsInTarget(*Aux)))) {
     if (A.isRegularKeywordAttribute() || A.isDeclspecAttribute()) {
-      S.Diag(A.getLoc(), A.isRegularKeywordAttribute()
-                             ? diag::err_keyword_not_supported_on_target
-                             : diag::warn_unhandled_ms_attribute_ignored)
+      S.Diag(A.getLoc(),
+             A.isRegularKeywordAttribute()
+                 ? (unsigned)diag::err_keyword_not_supported_on_target
+                 : (unsigned)diag::warn_unhandled_ms_attribute_ignored)
           << A << A.getRange();
     } else {
       S.DiagnoseUnknownAttribute(A);

@brunodf-snps
Copy link
Contributor Author

Tagging @erichkeane @Sirraide

@cor3ntin
Copy link
Contributor

@brunodf-snps @mstorsjo Please synchronize to avoid duplicates

Duplicate of #159338

@cor3ntin cor3ntin closed this Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants